<!DOCTYPE HTML>
<html>
   <head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>知果汇</title>
		<link href="_CSS_/bootstrap.min.css" rel="stylesheet">
		<link href="_CSS_/simple-line-icons.css" rel="stylesheet">
		<link href="_CSS_/font-awesome.min.css" rel="stylesheet">
		<link href="_CSS_/jasny-bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="_CSS_/nanoscroller.css">
		<link href="_CSS_/style.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="_CSS_/jquery-ui.css">
		<!--[if lt IE 9]>
		  <script src="_JS_/html5shiv.min.js"></script>
		  <script src="_JS_/respond.min.js"></script>
		<![endif]-->
		<style type="text/css">
		    body{background-color: #ffffff;}
			.row{margin-left: 0px;margin-right: 0px;}
			.radio-box{display:inline-block;width: 64px;}
			.formControls{padding-right:50px; position: relative;}
			.textarea {height: 100px;resize: none;font-size: 14px;padding: 4px;}
            .textarea-numberbar {position: absolute;right: 70px;bottom: 5px;z-index: 1;margin-bottom: 0;}
		</style>
    </head>
	<body>
	<article class="page-container">
		<form class="form form-horizontal" id="form-admin-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">标题：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" id="news_title" class="input-text" value="" placeholder="" id="headline" name="headline">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">新闻类别：</label>
				<div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
					<select id="news_type" class="select" name="newstype" size="1">
						<option value="1">国务院要闻</option>
						<option value="2">政策早知道</option>
						<option value="3">政策导读</option>
						<option value="4">工作报道</option>
						<option value="5">平台活动</option>
						<option value="6">国际要闻</option>
						<option value="7">知产学堂</option>
					</select>
					</span> </div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">新闻摘要：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<textarea id="news_adstract" name="abstract" cols="" rows="" class="textarea"  placeholder="请输入新闻摘要...20个字符以内" dragonfly="true" onKeyUp="textarealength(this,20)"></textarea>
					<p class="textarea-numberbar"><em class="textarea-length">0</em>/20</p>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">新闻内容：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<script id="editor" type="text/plain" style="width:100%;height:400px;"></script>
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;保存并发布&nbsp;&nbsp;">
					<input class="btn btn-warning radius" type="button" value="&nbsp;&nbsp;保存为草稿&nbsp;&nbsp;">
					<input class="btn btn-default radius" style="color: #ffffff;background-color: #a0a0a0;" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>

<!--_footer 作为公共模版分离出去-->
    <script src="_JS_/jquery.min.js"></script>
	<!-- <script src="_JS_/jquery.form.js"></script> -->
	<script src="_JS_/jquery.base64.js"></script>
    <script src="_JS_/jquery.cookie.js"></script>
    <script src="_JS_/bootstrap.min.js"></script>
    <script src="_JS_/jasny-bootstrap.min.js"></script>
    <script src="_JS_/jquery.slimscroll.min.js"></script>
    <script src="_JS_/jquery.nanoscroller.min.js"></script>
    <script src="_JS_/metismenu.min.js"></script>
    <script src="_JS_/float-custom.js"></script>
    <script type="text/javascript" src="_JS_/layer/layer.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script src="_JS_/ueditor/1.4.3/ueditor.config.js"></script>
    <script src="_JS_/ueditor/1.4.3/ueditor.all.min.js"> </script>
   <script src="_JS_/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
var url=window.location.href;
    id = url.split("#")[1];
    user_id = url.split("#")[2];

	$(function(){
        //文本编辑器
		 editor1 = UE.getEditor('editor',{
			toolbars: [[
				'source', '|', 'undo', 'redo', '|',
				'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', '|',
				'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
				'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
				'directionalityltr', 'directionalityrtl', 'indent', '|',
				'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
				'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
				'insertimage',  'scrawl',  'insertframe','music', 'attachment', 'map', 'insertcode', 'pagebreak', 'template', 'background', '|',
				'horizontal', 'date', 'time', 'spechars','|',
				'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
				'searchreplace','cleardoc','preview',
			]],
			initialFrameHeight:300});



	    //新闻详情加载
	    $.ajax({
	        type: "get",
	        url: "{:url('api/news/government_detail')}",
	        dataType: 'jsonp',
			jsonp:'callback',
	        data:{'id':id},
	        success: function (msg) {
	            if(msg.code == 200){
                    //编辑器准备好之后加载内容
					editor1.ready(function () {
						editor1.setContent(msg.data.content);
					});
	            	//editor1.addListener("ready", function () {
	            	//  editor1.setContent(msg.data.content);
	            	//});
				    $('#news_title').val(msg.data.title);
				    $('#news_adstract').val(msg.data.abstract);
				    $('#news_type').val(msg.data.type);
	            }
	            if(msg.code==1000){
	                layer.msg(msg.message,{icon:5,time:2000});
	            }
	        }
	    });

	});
	/*textarea 字数限制*/
	function textarealength(obj,maxlength){
		var v = $(obj).val();
		var l = v.length;
		if( l > maxlength){
			v = v.substring(0,maxlength);
			$(obj).val(v);
		}
		$(obj).parent().find(".textarea-length").text(v.length);
	}
	/*发布按钮*/
	$('.btn-primary').on('click',function(){
		button(1);
	});
	/*保存按钮*/
	$('.btn-warning').on('click',function(){
		button(2);
	});
	/*取消按钮*/
	$('.btn-default').on('click',function(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	});
	function button(status){
		var content = editor1.getContent();
		var str2 = encodeURIComponent(content);
		    headline=$('#news_title').val();
		    abstract=$('#news_adstract').val();
		    newstype=$('#news_type').val();
		    uid=user_id;
		if(headline!=""&&abstract!=""&&content!=""){
			$.ajax({
				url:"{:url('api/news/government_edit')}",
				type: "post",
				dataType:"json",
				data:{
					"id":id,
					"content":str2,
					"status":status,
					"headline":headline,
					"abstract":abstract,
					"newstype":newstype,
					"uid":uid
				},
				success: function(msg){
					if(msg.code == 200){
		            	var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						parent.window.location.reload();
		            }
		            if(msg.code==1000){
		                layer.msg(msg.message,{icon:5,time:1000});
		            }
				},
				error: function(){
					layer.closeAll();
					layer.msg('网络错误');
				}
			});
	    }else{
	    	layer.msg('请完善发布内容!',{icon:0,time:1000})
	    }
	}

</script>
</body>
</html>